package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	file, err := os.Open("/Users/huangzhe/Downloads/pedge_cost.txt")
	if err != nil {
		fmt.Printf("打开文件失败， err：%v \n", err)
		return
	}

	defer file.Close() // 在 main() 方法执行结束后关闭，不论是否发生错误

	// 业务逻辑
	reader := bufio.NewReader(file)
	fmt.Printf("reader 的类型：%T \n", reader)

	totalHour := 0
	totalCount := 0
	for {
		line, err2 := reader.ReadString('\n')
		if err2 != nil {
			fmt.Printf("读取数据失败， err：%v \n", err2)
			break
		}
		times := strings.Split(line, ":")
		hour, _ := strconv.Atoi(times[0])
		totalHour += hour
		totalCount++
	}

	fmt.Printf("总耗时：%v（小时），平均耗时：%v（小时）\n", totalHour, totalHour/totalCount)

}
